#include "../Main.h"
#include "Screen.h"

bool Screen::DisplaySurface(SDL_Surface* image, int x, int y, SDL_Rect area) {
	SDL_Rect point;
	point.x = x;
	point.y = y;
	if (SDL_BlitSurface(image, &area, screen, &point) < 0)
		return DebugMessageSDL("Interface", "DisplaySurface", error);
	return true;
}

bool Screen::DisplaySurface(SDL_Surface* image, int x, int y, int imgX, int imgY, int imgW, int imgH) {
	SDL_Rect area;
	area.w = imgW == -1 ? image->w : imgW;
	area.h = imgH == -1 ? image->h : imgH;
	area.x = imgX;
	area.y = imgY;
	return DisplaySurface(image, x, y, area);
}

SDL_Surface* Screen::PrepareText(const char* text, TTF_Font* font, unsigned r, unsigned g, unsigned b) {
    SDL_Color color;
    color.r = r;
    color.g = g;
    color.b = b;
    return TTF_RenderText_Blended(font, text, color);
}

void Screen::WriteText(const char* text, SDL_Surface* screen, TTF_Font* font, unsigned x, unsigned y, unsigned r, unsigned g, unsigned b) {
    SDL_Surface* textSurf = PrepareText(text, font, r, g, b);
    SDL_Rect dstrect;
    dstrect.x = x;
    dstrect.y = y;

    SDL_BlitSurface(textSurf, 0, screen, &dstrect);
    SDL_FreeSurface(textSurf);
}

void CentreScreen::WriteText(const char* text, SDL_Surface* screen, TTF_Font* font, unsigned x, unsigned y, unsigned r, unsigned g, unsigned b) {
	Screen::WriteText(text, screen, font, x, y, r, g, b);
}